#include "dialog.h"
#include <QApplication>
#include <QtCore/QObject>
#include "CaesarCipher.h"
#include <QMediaPlayer>
#include<QThread>
#include "root.h"

//初始化单例对象---Singleton
CaesarCipher* CaesarCipher::instance=nullptr;


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Dialog w;
    w.setWindowTitle("Consumer Login");
    w.show();

    root w1;
    w1.setWindowTitle("Adminer Login");


    //连接menuview和admin界面的2个窗口
    QObject::connect(w.returnMenuview(),SIGNAL(sitdown(std::string)),w1.getDialog()->returnAdmin(),SLOT(slot_sitdown(std::string)));
    QObject::connect(w.returnMenuview(),SIGNAL(SubmitOrder(std::string,std::string)),w1.getDialog()->returnAdmin(),SLOT(slot_SubmitOrder(std::string,std::string)));
    QObject::connect(w.returnMenuview(),SIGNAL(Pay(uint64_t,std::string)),w1.getDialog()->returnAdmin(),SLOT(slot_Pay(uint64_t,std::string)));
    QObject::connect(w.returnMenuview(),SIGNAL(Callwaiter(std::string)),w1.getDialog()->returnAdmin(),SLOT(slot_Callwaiter(std::string)));
    QObject::connect(w1.getDialog()->returnAdmin(),SIGNAL(State(uint64_t)),w.returnMenuview(),SLOT(slot_State(uint64_t)));
    QObject::connect(w1.getDialog()->returnAdmin(),SIGNAL(ModifyDesk(int)),w.returnMenuview(),SLOT(slot_Modify(int)));

    // 创建一个 QThread 对象
    QThread thread;
    // 将 w1 对象移动到子线程中
    w1.moveToThread(&thread);
    // 在子线程中显示 w1 窗口
    QObject::connect(&thread, &QThread::started, &w1, &Dialog::show);
    // 启动子线程
    thread.start();

    auto music=[]()
    {
        // 创建一个 QMediaPlayer 对象
        QMediaPlayer *player = new QMediaPlayer;

        // 设置音乐文件"D:\音乐\一直很安静.mp3"
        player->setSource(QUrl::fromLocalFile("D:\\音乐\\一直很安静.mp3"));

        // 开始播放音乐
        player->play();
    };

    return a.exec();
}
